package com.cskaoyan.wx.service;

import com.cskaoyan.bean.Goods;
import com.cskaoyan.bean.Topic;
import com.cskaoyan.bean.TopicExample;
import com.cskaoyan.mapper.TopicMapper;
import com.cskaoyan.wx.bean.vo.WxTopicDetailVo;
import com.cskaoyan.wx.bean.vo.WxTopicRelatedVo;
import com.cskaoyan.wx.bean.vo.WxTopicVo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者：whl
 * 功能：
 */
@Service
public class WxTopicServiceImpl implements WxTopicService {
    @Autowired
    TopicMapper topicMapper;

    @Override
    public WxTopicVo topList(Integer page, Integer size) {//返回参数：count、data
        PageHelper.startPage(page,size);
        //构造条件
        TopicExample topicExample = new TopicExample();
        long count = topicMapper.countByExample(topicExample);

        List<Topic> data = topicMapper.selectByExample(topicExample);

        WxTopicVo topicVo = new WxTopicVo();
        topicVo.setCount(count);
        topicVo.setData(data);
        return topicVo;
    }

    @Override
    public WxTopicDetailVo topicDetail(Integer id) {//goods、topic

        Topic topic = topicMapper.selectByPrimaryKey(id);

        Goods goods = new Goods();
        WxTopicDetailVo detailVo = new WxTopicDetailVo();
        detailVo.setTopic(topic);
        detailVo.setGoods(goods);
        return detailVo;
    }

    @Override
    public WxTopicRelatedVo topicRelated(Integer id) {
        TopicExample topicExample = new TopicExample();
        List<Topic> topics = topicMapper.selectByExample(topicExample);


        WxTopicRelatedVo relatedVo = new WxTopicRelatedVo();
        relatedVo.setData(topics);
        return relatedVo;
    }
}
